package com.heyqing.topic.ReverseVowels_0345;

import java.util.Arrays;
import java.util.List;

/**
 * ClassName:ReverseVowels
 * Package:com.heyqing.topic.ReverseVowels_0345
 * Description:
 *
 * @Date:2024/9/27
 * @Author:Heyqing
 */
public class ReverseVowels {
    public String reverseVowels(String s) {
        List<String> flag = Arrays.asList("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
        int start = 0, end = s.length() - 1;
        String[] str = s.split("");

        boolean startFlag = false, endFlag = false;
        while (start <= end) {
            if (startFlag && endFlag){
                String t = str[end];
                str[end] = str[start];
                str[start] = t;
                start++;
                end--;
                startFlag = false;
                endFlag = false;
            }
            if (start > end) break;
            if (!flag.contains(str[start])){
                start++;
            }else {
                startFlag = true;
            }
            if (!flag.contains(str[end])){
                end--;
            }else {
                endFlag = true;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (String elem : str) {
            sb.append(elem);
        }
        return sb.toString();
    }
}
